package com.whmnx.my.ui.viewmodel;


import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.whmnx.base.bean.JiaoYiBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.ui.fragment.FabuShouGouFragment;

import java.util.HashMap;
import java.util.Map;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 *
 * @author goldze
 * @date 2018/7/18
 */

public class ViewPagerItemJiaoYiViewModel extends ItemViewModel<JiaoYiModel> {
    public String text;

    //交易价格
    public ObservableField<String> textPrice = new ObservableField<>("");

    public ObservableField<String> textNum = new ObservableField<>("");
    public ObservableField<String> text1 = new ObservableField<>("");
    public ObservableField<String> text2 = new ObservableField<>("");


    //用户名的绑定
    public ObservableField<String> textttt = new ObservableField<>("发布播豆收购");

    public ViewPagerItemJiaoYiViewModel(@NonNull JiaoYiModel viewModel, int index) {
        super(viewModel);
        if (index == 1){
            text1.set("收购总金额（元）");
            text2.set("收购总数量（个）");
        }else {
            text1.set("出售总金额（元）");
            text2.set("出售总数量（个）");
        }

        getDeallist(index);
    }

    private void getDeallist(int index) {
        Map<String, Object> params = new HashMap<>();
        params.put("deal_Type",index - 1);
        params.put("pageIndex",1);
        params.put("pageSize",20);
        params.put("userId", SPUtils.getInstance().getString(Constants.USERID));
        HttpClient.post(viewModel.getApplication(), Constants.DEALLISTTOUSER, params,new CallBack<JiaoYiBean>() {
            @Override
            public void onSuccess(JiaoYiBean result) {
                textPrice.set(result.Money);
                textNum.set(result.Num);
                if (result.getRecordList().size() > 0){
                    for (JiaoYiBean.RecordListBean recordListBean : result.getRecordList()) {
                        observableList.add(new JiaoYiItemViewModel(viewModel,recordListBean));
                    }
                }
            }
        });
    }

    //给RecyclerView添加ObservableList
    public ObservableList<JiaoYiItemViewModel> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding
    public ItemBinding<JiaoYiItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.grid_jiaoyi);
}
